package com.aso114.project.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BaseApplication;
import com.aso114.project.base.BasesAdapter;
import com.aso114.project.bean.QuestionBean;
import com.aso114.project.bean.QuestionContextListBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by asus on 2019/1/16.
 */

public class ExpositionAdapter extends BasesAdapter<ExpositionAdapter.ViewHolder> {

    private OnItemClickListener mListener;

    private ArrayList<QuestionContextListBean> baseListBean = new ArrayList<>();

    private int mPosition = 0;

    public ExpositionAdapter(Context context, ArrayList<QuestionContextListBean> baseListBean,int position) {
        super(context);
        this.baseListBean = baseListBean;
        this.mPosition = position;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getInflater().inflate(R.layout.expostion_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.expostionItemText.setText("材料" + (position + 1));
        if (mPosition == position){
            holder.expostionItemText.setTextColor(BaseApplication.getInstance().getResources().getColor(R.color.aff6559));
        }else {
            holder.expostionItemText.setTextColor(BaseApplication.getInstance().getResources().getColor(R.color.a999999));
        }
        holder.expostionItemText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    if (mListener != null) {
                        mListener.onItemClick(position);
                        mPosition = position;
                    }
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return baseListBean.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.expostion_item_text)
        TextView expostionItemText;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        mListener = listener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
